package com.jintian.smart.kernel.orm.mapper.internal;

import java.lang.reflect.Method;
import java.util.List;

import org.beetl.sql.clazz.kit.AutoSQLEnum;
import org.beetl.sql.clazz.kit.BeetlSQLException;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.page.PageRequest;
import org.beetl.sql.mapper.MapperInvoke;

/**
 * 模板分页查询
 */
public class TemplatePageQueryAMI extends MapperInvoke {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Object call(SQLManager sm, Class entityClass, Method m, Object[] args) {
		if (!(args[1] instanceof List)) {
			throw new BeetlSQLException(BeetlSQLException.MAPPING_ERROR, "期望第二个参数是PageRequest");
		}
		SqlId sqlId = sm.getSqlIdFactory().buildIdentity(entityClass, AutoSQLEnum.SELECT_BY_TEMPLATE);
		return sm.pageQuery(sqlId, entityClass, args[1], (PageRequest) args[0]);
	}
}
